package com.hex.ds.em.hcdp.gauss.starter;

import com.hex.ds.em.hcdp.gauss.pack.service.impl.ScriptPackTaskServiceImpl;
import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author : ky.zhang
 * @description :
 * @createDate : 2024/8/27 14:41
 */
@Component
public class MyStarter {
    private final ApplicationContext applicationContext;
    private final ScriptPackTaskServiceImpl scriptPackTaskService;

    public MyStarter(ApplicationContext applicationContext, ScriptPackTaskServiceImpl scriptPackTaskService) {
        this.applicationContext = applicationContext;
        this.scriptPackTaskService = scriptPackTaskService;
    }

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReadyEvent() throws IOException, InvalidFormatException {
        scriptPackTaskService.scanFile();
        int exitCode = SpringApplication.exit(applicationContext, () -> 0);
        System.exit(exitCode);
    }
}
